package com.dnjn.happiness.emo.controller.common;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.annotation.RequiresPermissions;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import com.dnjn.happiness.emo.domain.EmoHscoreLog;
import com.dnjn.happiness.emo.domain.vo.EmoHscoreLogVO;
import com.dnjn.happiness.emo.service.IEmoHscoreLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;

/**
 * 快乐分波动记录Controller
 *
 * @author happiness
 * @date 2024-04-15
 */

@Slf4j
public class CommonEmoHscoreLogController extends BaseController {
    @Autowired
    protected IEmoHscoreLogService emoHscoreLogService;

    /**
     * 查询快乐分波动记录列表
     */
    @Log(title = "快乐分波动记录", businessType = BusinessType.LIST)
    @RequiresPermissions("@ss.hasAnyPermi('emo:scoreLog:list,ignore:scoreLog:list')")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody EmoHscoreLogVO vo, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        EmoHscoreLog emoHscoreLog = new EmoHscoreLog();
        BeanUtils.copyPropsIgnoreNull(vo, emoHscoreLog);
        Page page = Page.of(current, size);
        Page<EmoHscoreLog> list = emoHscoreLogService.page(page, Wrappers.query(emoHscoreLog));
        return success(list);
    }

    /**
     * 获取快乐分波动记录详细信息
     */
    @Log(title = "快乐分波动记录", businessType = BusinessType.SELECT)
    @RequiresPermissions("@ss.hasAnyPermi('emo:scoreLog:query,ignore:scoreLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult get(@PathVariable("id") Long id) {
        return success(emoHscoreLogService.getById(id));
    }

    /**
     * 新增快乐分波动记录
     */
    @Log(title = "快乐分波动记录", businessType = BusinessType.INSERT)
    @RequiresPermissions("@ss.hasAnyPermi('emo:scoreLog:add,ignore:scoreLog:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody EmoHscoreLogVO vo) {
        EmoHscoreLog emoHscoreLog = new EmoHscoreLog();
        BeanUtils.copyPropsIgnoreNull(vo, emoHscoreLog);

        emoHscoreLog.setCreateBy(SecurityUtils.getUsername());
        return toAjax(emoHscoreLogService.save(emoHscoreLog));
    }

    /**
     * 修改快乐分波动记录
     */
    @Log(title = "快乐分波动记录", businessType = BusinessType.UPDATE)
    @RequiresPermissions("@ss.hasAnyPermi('emo:scoreLog:edit,ignore:scoreLog:edit')")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody EmoHscoreLogVO vo) {
        EmoHscoreLog emoHscoreLog = new EmoHscoreLog();
        BeanUtils.copyPropsIgnoreNull(vo, emoHscoreLog);
        return toAjax(emoHscoreLogService.updateById(emoHscoreLog));
    }

    /**
     * 删除快乐分波动记录
     */
    @Log(title = "快乐分波动记录", businessType = BusinessType.DELETE)
    @RequiresPermissions("@ss.hasAnyPermi('emo:scoreLog:remove,ignore:scoreLog:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(emoHscoreLogService.removeBatchByIds(Arrays.asList(ids)));
    }
}